package com.neutech.neufin.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.neutech.po.SettleCategory;


@RestController
@CrossOrigin("http://localhost:8081")//允许跨域请求的地址
@RequestMapping("/neuhis/settle")
public class SettleCategoryController {
	@Autowired
	private com.neutech.neufin.service.SettleCategoryService settleCategoryService;
	@RequestMapping(value="/add",method=RequestMethod.POST)
	public String addNewSettle(SettleCategory settleCategory){
		int result = settleCategoryService.addNewSettle(settleCategory);
		if(result == 1){
			return "success";
		}else{
			return "error";
		}
	}
	
//	通过接收得id查找相信信息
//	@return:单独用户数据
	@RequestMapping(value="/toupdate",method=RequestMethod.GET)
	public String updateSettleById(SettleCategory settleCategory){
		int result = settleCategoryService.updateSettle(settleCategory);
		if(result>0){
			return "成功";
		}else{
			return "失败";
		}
	}
	
	/*得到所有用户
	 * @return:用户对象集合
	 * */
	@RequestMapping(value="/queryAllSettle",method=RequestMethod.GET)
	public List<SettleCategory> queryAllSettle(){	
		return settleCategoryService.queryAllSettle();
	}
	
	@RequestMapping(value="/selectSettle",method=RequestMethod.GET)
	public SettleCategory findSettleById(int id){
		try {
			return settleCategoryService.findSettleById(id);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return new SettleCategory();
		
	}
	
	@RequestMapping(value="/deleteSettle",method=RequestMethod.GET)
	public String deleteSettleById(int id){	
		int result = settleCategoryService.deleteSettleById(id);
		if(result>0){
			return "success";
		}else{
			return "失败";
		}
	}
}
